from django.shortcuts import redirect
from django.urls import reverse


def login_required(view_func):
    def wrapper(request, *view_args, **view_kwargs):
        # 检查session中是否有 islogin
        if request.session.has_key('islogin'):
        # if 'islogin' in request.session:
            # 已登录
            return view_func(request, *view_args, **view_kwargs)
        else:
            # 未登录
            # return redirect('/user/login/')
            return redirect(reverse('login'))
    return wrapper
